<<<<<<< .mine
SortLevel.prototype = new Sprite();

function SortLevel(type){
    this.name = "levelSort";
    this.picturePath = Game.picturesPath + "levels/"+this.name + "/";
    Sprite.apply(this); 
    Level.apply(this);
    this.requiredTime = 60;
    this.type = type;
    this.numbers = new Array();
    this.selectedNumber = null;
    this.solved = false;
    this.manual = new Manual (this.picturePath);
    
    // methods association
    this.init = init;
    this.isSolved = isSolved;
    this.numberOrd = numberOrd;
    this.numberMouseOver = numberMouseOver;
    this.numberMouseExit = numberMouseExit;
    this.numberMouseClick = numberMouseClick;

    //methods
    function isSolved (){
        var tmp = new Array();
        tmp = this.numbers.concat(tmp);
        for (var i = 0;i < tmp.length;i++){
            if (tmp[i].val == null){
                tmp.splice(i, 1);
                break;
            }
        }
        for (var i = 0;i < tmp.length-1;i++){
                if (tmp[i].val > tmp[i+1].val)
                    return false;
            }
        this.timer.TimerStop();
        return true;
    }

    function init(){
        var centerY = MainContainerHeight / 2;        
        var beginX= (MainContainerWidth - 40*10)/2 + 20;
        for (var i = 0; i < 10;i++){
            if (i == 5){
                this.numbers.push(new Chlievik(null, beginX+i*40, centerY, 40,this.picturePath));
            }
            else{
                var rnd = Math.floor(Math.random()*100);
                this.numbers.push(new Chlievik(rnd, beginX+i*40, centerY, 40,this.picturePath));
            }
            
            this.numbers[i].addEventListener(MouseEvent.MOUSE_OVER, this.numberMouseOver,false);
            this.numbers[i].addEventListener(MouseEvent.MOUSE_OUT, this.numberMouseExit,false);
            this.numbers[i].addEventListener(MouseEvent.MOUSE_UP, this.numberMouseClick,false);
            this.addChild(this.numbers[i]);
        }
        this.addChild (this.manual); 

    }
    
    function numberOrd (number){
        for (var i = 0; i < this.numbers.length;i++){
            if (this.numbers[i] == number){
                return i;
            }
        }
        return -1;
    }
    
    //MouseHandlers
    function numberMouseOver (sender){
        sender.target.setClicked();
        console.log(sender.target);
    }
    
    function numberMouseExit (sender){
        var owner = sender.target.parent; 
        if (sender.target != owner.selectedNumber){ 
            sender.target.setUnClicked();
        }    
    }
    
    function numberMouseClick (sender){
        var owner = sender.target.parent;
        if (owner.selectedNumber === null){ 
            owner.selectedNumber = sender.target;
            owner.selectedNumber.setClicked();
        //owner.selectedNumber.currColor = owner.selectedNumber.eventColor;
        //owner.selectedNumber.draw();
        }
        else if (owner.selectedNumber == sender.target){
            //owner.selectedNumber.currColor = owner.selectedNumber.normalColor;
            //owner.selectedNumber.draw();
            owner.selectedNumber.setUnClicked();
            owner.selectedNumber = null;
        }
        else if (owner.selectedNumber != null && sender.target.val != null && owner.selectedNumber.val != null){
            //owner.selectedNumber.currColor = owner.selectedNumber.normalColor;
            //owner.selectedNumber.draw();
            owner.selectedNumber.setUnClicked();
            owner.selectedNumber = sender.target;
            owner.selectedNumber.setClicked();   
        }
        else {
            var iN1 =owner.numberOrd(owner.selectedNumber);
            var iN2 = owner.numberOrd(sender.target);
            if(Math.abs(iN1-iN2)<=2 && (owner.selectedNumber.val == null || sender.target.val == null)){
                if (owner.numbers[iN1].val == null){
                    owner.numbers[iN1].val = owner.numbers[iN2].val;
                    owner.numbers[iN2].val = null;
                }
                else{
                    owner.numbers[iN2].val = owner.numbers[iN1].val;
                    owner.numbers[iN1].val = null;
                }
                owner.numbers[iN1].updateText();
                owner.numbers[iN2].updateText();
                owner.selectedNumber = null;
                owner.numbers[iN1].setUnClicked();
                owner.numbers[iN2].setUnClicked();
                //owner.numbers[iN1].currColor = owner.numbers[iN1].normalColor;
                //owner.numbers[iN2].currColor = owner.numbers[iN2].normalColor;
                //owner.numbers[iN1].draw();
                //owner.numbers[iN2].draw();
                if (owner.isSolved()){
                    owner.levelSolved();
                //alert("Gratulujem!");
                }
            }
        }
    }
}

=======
SortLevel.prototype = new Sprite();
SortLevel.prototype = new Level ();
/**
*@class SortLevel
*@augments Level, Sprite 
*@param name nazov levelu
*@param levelOrd  poradove cislo levelu
*@param type typ levelu
*@description Zakladna trieda pre sortLevel
*/
function SortLevel(name, levelOrd, type){
    Sprite.apply(this); 
    Level.apply(this);
    this.name = name;
    this.levelOrd = levelOrd;
    this.type = type;
    this.numbers = new Array();
    this.selectedNumber = null;
    this.solved = false;
    
    // methods association
    this.init = init;
    this.isSolved = isSolved;
    this.numberOrd = numberOrd;
    this.numberMouseOver = numberMouseOver;
    this.numberMouseExit = numberMouseExit;
    this.numberMouseClick = numberMouseClick;
}

//methods
/**
@class SortLevel
@description Metoda zistujuca ci je level vyrieseny
 */
function isSolved (){
        for (var i = 0;i < this.numbers.length-1;i++){
            if (this.numbers[i].val == null){
                continue;
            }
            else if (this.numbers[i+1].val == null){
                if (i+1 == this.numbers.length)
                    continue;
                else{
                if (this.numbers[i].val > this.numbers[i+2].val)
                    return false;
                }
            }
            else{
                if (this.numbers[i].val > this.numbers[i+1].val)
                    return false;
            }
        }
        return true;
    }
/**
@class SortLevel
@description Metoda sluziaca k inicializacii levelu
 */
    function init(){
        var centerY = new Number(MainContainerHeight / 2);        
        var beginX= new Number ((MainContainerWidth- 50*10)/2);
        for (var i = 0; i < 10;i++){
            if (i == 5){
                this.numbers.push(new Chlievik(null, beginX+i*40, centerY, 40));
            }
            else{
                var rnd = Math.floor(Math.random()*100);
                this.numbers.push(new Chlievik(rnd, beginX+i*40, centerY, 40));
            }
            this.addChild(this.numbers[i]);
            this.numbers[i].addEventListener(MouseEvent.MOUSE_OVER, this.numberMouseOver);
            this.numbers[i].addEventListener(MouseEvent.MOUSE_OUT, this.numberMouseExit);
            this.numbers[i].addEventListener(MouseEvent.MOUSE_UP, this.numberMouseClick);
        }
    }
/**
@class SortLevel
@param number Chlievik, ktoreho poradove cislo v poli numbers chceme zistit    
@description Metoda zistujuca poradove cislo parametru number v poli numbers
 */    
    function numberOrd (number){
        for (var i = 0; i < this.numbers.length;i++){
            if (this.numbers[i] == number){
                return i;
            }
        }
        return -1;
    }
    
    //MouseHandlers
/**
@class SortLevel
@event MouseOver    
@description Metoda obsluhujuca mouseOver event
 */    
   function numberMouseOver (sender){
       sender.target.currColor = sender.target.eventColor
       sender.target.draw();
   }
/**
@class SortLevel
@event MouseExit    
@description Metoda obsluhujuca mouseExit event
 */        
    function numberMouseExit (sender){
        var owner = sender.target.parent; 
        if (sender.target !== owner.selectedNumber) 
            sender.target.currColor = sender.target.normalColor;
            sender.target.draw();
    }
/**
@class SortLevel
@event MouseClick    
@description Metoda obsluhujuca mouseClick event
 */    
    function numberMouseClick (sender){
        var owner = sender.target.parent;
        if (owner.selectedNumber === null){ 
            owner.selectedNumber = sender.target;
            owner.selectedNumber.currColor = owner.selectedNumber.eventColor;
            owner.selectedNumber.draw();
        }
        else if (owner.selectedNumber === sender.target){
            owner.selectedNumber.currColor = owner.selectedNumber.normalColor;
            owner.selectedNumber.draw();
            owner.selectedNumber = null;
            
        }
        else {
            var iN1 =owner.numberOrd(owner.selectedNumber);
            var iN2 = owner.numberOrd(sender.target);
            if(Math.abs(iN1-iN2)<=2 && (owner.selectedNumber.val == null || sender.target.val == null)){
                if (owner.numbers[iN1].val == null){
                    owner.numbers[iN1].val = owner.numbers[iN2].val;
                    owner.numbers[iN2].val = null;
                }
                else{
                    owner.numbers[iN2].val = owner.numbers[iN1].val;
                    owner.numbers[iN1].val = null;
                }
                owner.numbers[iN1].updateText();
                owner.numbers[iN2].updateText();
                owner.selectedNumber = null;
                owner.numbers[iN1].currColor = owner.numbers[iN1].normalColor;
                owner.numbers[iN2].currColor = owner.numbers[iN2].normalColor;
                owner.numbers[iN1].draw();
                owner.numbers[iN2].draw();
                if (owner.isSolved()){
                    alert("Gratulujem!");
                }
            }
        }
    }

>>>>>>> .r36
